<?php

/**
 * Louder Cache
 *
 * LICENSE
 *
 * This source file is subject to the New BSD License that is bundled
 * with this package in the file docs/LICENSE.txt.
 *
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to info@loudertechnology.com so we can send you a copy immediately.
 *
 * @category Louder
 * @package CacheNode
 * @copyright Copyright (c) 2005-2009 Andres Felipe Gutierrez (gutierrezandresfelipe at gmail.com)
 * @license New BSD License
 */

/**
 * Nodo del arbol de cache
 *
 * @category Louder
 * @package CacheNode
 * @copyright Copyright (c) 2005-2009 Andres Felipe Gutierrez (gutierrezandresfelipe at gmail.com)
 * @license New BSD License
 */
class CacheNode {

	/**
	 * CacheRefence al que pertence el nodo, su nombre no esta humanizado
	 * por motivos de rendimiento
	 *
	 * @var CacheReference
	 */
	private $_cr;

	/**
	 * ID del nodo en el arbol, su nombre no esta humanizado
	 * por motivos de rendimiento
	 *
	 * @var string
	 */
	private $_id;

	/**
	 * Constructor de la clase CacheNode
	 *
	 * @access public
	 * @param string $path
	 * @param mixed $value
	 */
	public function __construct($id){
		$this->_id = $id;
	}

	/**
	 * Establece el cacheReference
	 *
	 * @access public
	 * @param CacheReference $cacheReference
	 */
	public function setCacheReference(CacheReference $cacheReference){
		$this->_cr = $cacheReference;
	}

	/**
	 * Agrega un nodo hijo al nodo actual
	 *
	 * @access public
	 * @param FullyQualifiedName $fqn
	 * @return CacheNode
	 */
	public function addChild(FullyQualifiedName $fqn){
		return $this->_cr->addChild($this, $fqn);
	}

	/**
	 * Agrega un valor al nodo
	 *
	 * @access public
	 * @param string $index
	 * @param sting $value
	 * @return boolean
	 */
	public function put($index, $value){
		return $this->_cr->addNodeAttribute($this, (string) $index, $value);
	}

	/**
	 * Obtener el valor de un atributo del nodo
	 *
	 * @access public
	 * @param string $index
	 * @return mixed
	 */
	public function get($index){
		return $this->_cr->getNodeAttribute($this, (string) $index);
	}

	/**
	 * Devuelve la ubicacion interna donde reside el Nodo
	 *
	 * @access public
	 * @return string
	 */
	public function getId(){
		return $this->_id;
	}

}